﻿using System;

namespace SubCom_Doc2Pdf
{
    internal class ConvertorSwitcher
    {
        public Convertor switchTo(string[] args)
        {
            var target = new Target();
            target.Sources = args[0];
            if (args.Length == 1)
            {
                target.Destination = target.Sources + ".pdf";
            }
            else
            {
                target.Destination = args[1];
            }
           
            Convertor convertor = null;
            var dotLoc = target.Sources.LastIndexOf(".");
            string ext = null;
            if (dotLoc >= 0)
            {
                ext = target.Sources.Substring(dotLoc);
                Console.WriteLine(ext);
            }
            switch (ext)
            {
                case ".doc":
                case ".docx":
                    if (args.Length > 2)
                    {
                        if (args[2].Equals("-O"))
                        {
                            convertor = new Doc2PdfViaOffice(target);
                            break;
                        }
                        else if (args[2].Equals("-W"))
                        {
                            convertor = new Ppt2PdfViaWPS(target);
                            break;
                        }
                    }
                    convertor = new Doc2PdfViaOffice(target);
                    break;
                case ".xls":
                case ".xlsx":
                    convertor = new Xls2PdfViaOffice(target);
                    break;
                case ".ppt":
                case ".pptx":
                    convertor = new Ppt2PdfViaWPS(target);
                    break;
                case ".wps":
                    convertor = new Doc2PdfViaWPS(target);
                    break;
                default:
                    break;
            }

            return convertor;
        }
    }
}